/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Helper;

import java.awt.Component;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author luc0
 */
public class NumberTextFieldValidationListener implements FocusListener {
    private Component parent;
    private String value;
    public NumberTextFieldValidationListener(Component parent,String value){
        this.value = value;
        this.parent = parent;
    }
    public void focusGained(FocusEvent e) {
    }

    public void focusLost(FocusEvent e) {
        try {

            Integer.parseInt(((JTextField)e.getSource()).getText());
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(parent, "Please enter a valid "+value);
        }

    }
    public static boolean isNumberOfTextFieldValid(String number,int min, int max){
       boolean isValid = true;
        try {

            int value = Integer.parseInt(number);
            if(value >= min && value <= max){

            } else{
                isValid = false;
            }
        } catch (NumberFormatException ex) {
            isValid = false;
        }



        return isValid;
    }
}
